#if 0
	shc Version 4.0.3, Generic Shell Script Compiler
	GNU GPL Version 3 Md Jahidul Hamid <jahidulhamid@yahoo.com>

	shc -r -v -f clean_assets.sh 
#endif

static  char data [] = 
#define      shll_z	10
#define      shll	((&data[1]))
	"\072\302\054\330\244\103\230\277\235\147\275\220\056"
#define      inlo_z	3
#define      inlo	((&data[13]))
	"\244\122\177"
#define      xecc_z	15
#define      xecc	((&data[18]))
	"\042\072\135\361\175\253\034\146\131\170\375\055\354\056\373\257"
	"\073"
#define      lsto_z	1
#define      lsto	((&data[33]))
	"\344"
#define      tst1_z	22
#define      tst1	((&data[35]))
	"\114\342\304\056\001\350\151\264\112\240\276\072\101\373\051\274"
	"\156\235\034\054\205\044\344\027\316\056"
#define      msg2_z	19
#define      msg2	((&data[62]))
	"\062\255\030\335\273\041\004\133\107\372\277\053\122\065\177\133"
	"\170\216\025\372\351\120\203\361"
#define      tst2_z	19
#define      tst2	((&data[85]))
	"\170\336\337\120\237\274\215\162\060\325\371\137\157\306\314\160"
	"\250\016\017\060"
#define      chk1_z	22
#define      chk1	((&data[106]))
	"\022\311\072\146\170\336\244\226\224\000\002\274\352\266\313\306"
	"\246\203\326\220\021\306\040\272\123\113\354"
#define      rlax_z	1
#define      rlax	((&data[131]))
	"\063"
#define      opts_z	1
#define      opts	((&data[132]))
	"\044"
#define      text_z	2562
#define      text	((&data[243]))
	"\006\132\244\234\035\327\112\155\132\073\125\276\146\315\117\342"
	"\147\142\254\273\255\230\111\110\073\376\050\052\066\124\061\075"
	"\256\325\332\314\255\044\072\010\137\217\306\306\134\026\251\303"
	"\170\126\176\046\357\310\156\052\306\227\125\375\353\206\072\232"
	"\134\025\146\011\071\240\021\231\057\327\140\214\356\011\117\146"
	"\140\316\215\117\226\374\172\135\223\317\133\176\126\226\031\262"
	"\253\177\273\344\040\315\176\120\245\336\334\223\347\054\336\066"
	"\144\374\125\347\102\015\317\135\035\341\367\353\236\250\223\030"
	"\324\020\374\025\215\030\052\102\051\114\122\244\111\323\302\123"
	"\202\115\073\100\210\043\167\367\172\046\166\100\147\063\060\061"
	"\051\113\320\176\347\012\020\373\353\041\330\245\205\127\331\164"
	"\240\036\002\164\016\145\160\165\006\166\131\015\315\310\136\143"
	"\356\277\034\214\270\235\311\373\376\142\310\012\342\136\322\064"
	"\126\260\215\056\357\140\204\160\122\006\350\057\341\124\365\176"
	"\311\343\064\222\275\166\050\360\144\373\211\317\224\120\275\265"
	"\177\302\121\127\051\365\027\017\003\376\074\211\217\245\162\032"
	"\217\365\237\057\325\123\075\244\271\347\223\170\221\242\231\161"
	"\342\145\325\155\136\013\016\131\002\272\250\050\144\221\144\010"
	"\371\145\133\374\041\210\310\321\021\001\300\064\214\375\000\303"
	"\260\203\043\151\254\363\035\067\354\332\340\364\370\357\251\376"
	"\236\174\151\235\012\005\222\027\064\056\155\142\165\123\242\376"
	"\240\313\132\065\210\122\305\161\277\013\104\225\231\200\036\153"
	"\233\104\320\110\101\073\133\035\253\312\027\243\160\221\307\044"
	"\377\252\301\026\351\237\007\253\120\024\320\310\362\145\132\256"
	"\230\226\154\016\340\366\157\021\115\304\350\227\124\026\345\022"
	"\030\144\246\041\331\104\363\310\342\146\121\221\133\054\227\024"
	"\033\364\177\346\346\353\211\024\171\022\246\133\324\342\374\227"
	"\356\341\325\055\074\173\051\374\242\273\220\001\054\104\260\057"
	"\253\140\331\227\355\057\036\023\160\153\161\141\016\220\273\332"
	"\005\075\171\307\056\175\027\213\360\044\155\037\243\132\276\046"
	"\202\103\232\364\364\035\122\225\200\274\023\111\265\241\231\025"
	"\311\322\304\261\225\301\376\317\100\373\025\165\344\366\363\153"
	"\126\307\005\156\001\232\122\246\256\301\353\247\166\027\024\010"
	"\240\302\125\064\002\140\214\323\166\365\226\313\125\332\314\076"
	"\101\010\001\357\317\324\210\230\354\172\154\051\244\377\314\122"
	"\033\056\376\030\231\326\014\205\003\033\336\313\016\131\254\204"
	"\177\013\311\335\325\366\200\063\150\346\014\167\101\306\206\220"
	"\027\375\021\302\054\243\030\161\347\322\077\052\011\020\144\323"
	"\224\220\364\102\302\020\005\272\000\172\374\262\036\365\222\365"
	"\022\025\036\176\347\055\072\123\031\251\124\353\164\062\272\350"
	"\366\142\304\140\050\024\204\174\004\055\336\241\372\242\157\203"
	"\356\147\157\363\207\257\176\025\365\225\001\155\060\033\035\165"
	"\200\364\343\115\264\035\041\274\245\012\314\017\037\042\345\317"
	"\065\160\300\260\347\363\156\145\071\262\063\165\220\317\027\365"
	"\372\024\224\176\124\152\341\140\122\261\330\164\006\015\303\255"
	"\373\253\110\306\040\024\305\166\054\225\317\250\335\334\371\302"
	"\204\111\367\144\165\362\276\035\266\006\231\140\302\223\163\331"
	"\274\137\361\202\230\011\015\313\157\104\132\111\310\023\066\272"
	"\267\134\354\043\161\276\107\126\350\167\261\126\070\202\002\010"
	"\055\277\201\132\170\244\173\203\336\333\043\044\271\337\111\321"
	"\124\350\314\117\307\232\120\377\107\070\305\202\145\051\171\056"
	"\344\116\152\225\101\277\037\027\271\052\317\355\243\165\155\140"
	"\134\271\367\107\300\174\347\264\301\066\351\271\314\305\023\016"
	"\126\047\212\354\374\311\363\371\213\162\060\110\130\372\134\254"
	"\347\302\143\217\165\346\356\327\253\322\313\277\236\067\316\223"
	"\261\003\374\037\351\141\363\113\344\044\362\364\116\225\075\215"
	"\176\340\004\032\245\235\023\256\370\046\075\313\040\064\072\261"
	"\252\306\250\320\200\243\007\061\041\340\033\001\063\157\152\003"
	"\160\137\107\333\130\341\225\273\171\100\110\347\367\003\106\135"
	"\211\170\020\031\014\312\203\063\106\044\067\165\004\306\015\004"
	"\162\054\154\225\164\272\217\123\364\363\302\207\351\361\114\352"
	"\311\023\003\323\327\356\216\304\064\355\123\312\364\351\050\240"
	"\117\112\042\260\365\272\274\142\370\163\305\331\147\335\135\170"
	"\174\357\260\234\373\077\360\071\102\372\070\110\240\323\307\374"
	"\222\363\305\027\302\042\335\335\327\163\344\026\254\303\377\323"
	"\272\340\153\121\311\211\276\372\214\272\201\046\214\207\350\027"
	"\117\271\173\106\047\267\045\014\220\353\357\214\165\357\071\023"
	"\167\366\276\165\315\326\005\256\176\337\240\150\234\112\010\256"
	"\003\242\306\150\347\354\041\370\101\065\064\336\055\007\031\335"
	"\141\351\237\252\170\155\142\221\375\064\363\135\352\320\340\020"
	"\001\011\076\173\336\100\162\077\165\207\141\110\105\374\361\224"
	"\027\074\254\325\336\337\236\141\242\241\033\130\107\115\131\321"
	"\272\230\026\076\322\003\111\173\233\122\311\236\376\176\313\357"
	"\147\030\372\073\222\123\302\370\307\252\170\113\270\355\161\273"
	"\126\043\343\331\220\075\156\116\140\323\243\357\105\134\207\061"
	"\300\050\124\020\303\374\042\166\070\021\007\340\154\024\363\012"
	"\106\343\362\066\221\077\036\331\150\364\033\251\240\317\356\146"
	"\162\056\271\262\265\252\264\173\360\206\035\372\226\022\371\070"
	"\007\061\324\117\305\365\105\213\240\343\012\237\022\252\351\104"
	"\040\034\222\175\275\231\013\206\041\331\011\004\205\274\025\010"
	"\141\105\115\040\027\100\104\046\160\323\241\103\271\040\200\014"
	"\301\260\332\314\065\141\327\157\311\262\156\303\361\111\172\156"
	"\104\251\324\044\143\307\277\222\143\367\317\104\115\270\324\200"
	"\267\071\305\207\121\253\046\264\326\017\167\336\177\031\211\145"
	"\070\154\170\341\214\315\337\143\265\360\315\077\107\006\145\114"
	"\067\306\132\344\176\323\343\246\040\120\125\100\127\122\342\077"
	"\333\263\164\173\114\343\267\026\200\163\223\204\310\021\074\126"
	"\234\141\024\332\274\032\112\225\057\177\103\154\217\300\306\104"
	"\363\211\276\115\076\142\107\015\027\163\043\113\222\065\052\361"
	"\045\276\362\336\025\213\136\073\304\106\115\053\147\312\207\011"
	"\333\302\356\355\077\061\075\270\267\066\160\162\134\203\016\112"
	"\072\276\347\024\140\221\020\106\114\211\350\272\151\355\360\120"
	"\333\362\175\245\267\324\216\007\357\146\137\116\225\302\105\133"
	"\124\344\335\215\102\340\230\102\002\211\171\225\226\232\206\044"
	"\106\265\167\024\064\274\173\071\205\027\261\316\004\354\010\176"
	"\044\003\227\275\050\000\251\147\023\345\102\130\251\020\012\006"
	"\045\012\326\037\271\222\277\066\313\145\076\100\125\357\241\247"
	"\031\313\123\140\320\237\143\056\037\221\151\324\177\007\157\355"
	"\015\370\317\377\331\160\171\157\033\013\140\127\136\105\234\262"
	"\327\021\241\072\101\163\274\204\273\035\160\327\034\315\341\215"
	"\064\221\043\170\022\113\277\375\162\000\323\316\021\252\236\141"
	"\132\237\155\226\347\147\321\253\165\304\123\126\261\032\033\374"
	"\153\355\024\226\272\177\156\336\245\075\072\050\110\070\065\302"
	"\311\343\273\254\317\050\342\005\122\253\145\147\372\157\163\153"
	"\121\262\214\055\163\172\265\220\150\023\345\347\060\034\346\100"
	"\353\042\354\017\255\010\204\026\306\075\212\325\315\070\370\075"
	"\127\230\303\236\052\345\305\323\341\173\146\103\017\126\241\146"
	"\263\140\335\002\130\104\315\263\072\171\266\244\131\127\120\067"
	"\221\351\035\366\141\226\037\017\222\026\147\111\242\043\217\033"
	"\045\162\175\243\120\161\330\166\124\266\222\107\164\225\123\130"
	"\042\314\111\016\002\352\174\321\271\030\003\232\365\126\251\343"
	"\153\031\057\161\106\074\130\102\312\071\262\033\330\053\163\073"
	"\060\356\375\064\122\203\242\177\316\240\103\201\257\112\043\166"
	"\123\046\056\101\051\253\152\154\133\007\165\237\040\166\052\240"
	"\375\340\231\117\175\304\157\032\217\011\017\323\023\165\072\213"
	"\356\147\045\200\060\025\250\201\370\320\342\063\005\021\173\374"
	"\354\343\265\100\207\055\124\316\047\066\331\326\151\254\013\227"
	"\043\222\125\335\331\176\323\101\212\132\011\043\155\250\302\251"
	"\013\230\137\177\170\367\370\120\005\240\047\072\035\047\152\016"
	"\160\124\230\333\176\177\322\101\143\042\062\253\102\305\354\014"
	"\243\174\307\044\273\370\160\241\066\370\360\156\134\211\117\316"
	"\224\310\006\035\027\371\257\017\377\361\334\243\041\106\104\215"
	"\057\011\213\257\341\223\155\072\201\346\170\171\342\233\160\373"
	"\005\340\366\130\332\107\060\050\217\273\140\022\326\034\211\000"
	"\007\232\221\074\371\263\067\306\106\246\315\061\063\005\025\063"
	"\061\312\213\214\311\076\001\243\164\054\371\225\017\130\366\272"
	"\100\260\017\234\133\121\372\162\253\050\350\206\065\374\167\176"
	"\150\063\042\027\376\317\016\207\327\361\131\134\346\367\014\117"
	"\233\335\202\330\267\250\154\342\201\026\071\052\375\164\236\143"
	"\303\264\152\262\047\306\244\250\040\332\142\136\373\325\133\264"
	"\364\106\333\322\322\156\306\107\374\012\245\147\211\120\151\223"
	"\312\130\315\200\273\073\365\157\000\230\312\114\202\116\157\142"
	"\021\302\171\302\074\254\254\257\256\173\325\123\273\355\121\050"
	"\072\054\257\123\333\155\142\144\177\332\161\006\002\361\314\215"
	"\034\345\236\024\031\270\223\351\173\330\037\261\243\216\053\205"
	"\027\046\217\035\235\206\226\177\042\037\370\133\060\211\347\341"
	"\027\062\310\311\140\211\140\341\034\373\236\362\034\077\150\276"
	"\235\212\227\120\020\255\342\035\307\154\215\256\307\216\012\113"
	"\210\152\100\005\133\232\364\175\055\016\110\004\217\305\105\307"
	"\050\301\250\171\354\041\327\104\267\073\065\174\055\265\064\111"
	"\076\061\173\123\365\372\013\136\012\107\216\363\357\154\020\122"
	"\127\321\124\033\136\070\004\206\011\102\140\305\216\245\251\210"
	"\125\015\057\240\315\221\365\027\220\035\101\314\344\260\111\216"
	"\154\342\303\112\013\356\164\143\051\352\262\342\376\356\056\020"
	"\121\063\345\114\027\043\135\333\111\245\107\226\073\034\015\340"
	"\056\302\340\333\361\145\010\315\122\311\165\336\212\367\013\220"
	"\044\251\061\122\345\075\226\232\006\234\157\206\202\016\306\305"
	"\320\030\273\372\307\002\062\341\051\123\204\001\166\366\315\043"
	"\340\341\131\254\345\324\106\224\343\025\146\211\111\237\301\275"
	"\311\354\203\157\001\244\115\364\057\034\120\363\055\075\022\064"
	"\253\224\244\211\137\332\022\106\203\252\370\216\237\376\035\165"
	"\263\142\336\306\001\217\225\320\303\007\055\345\032\311\376\136"
	"\134\302\043\156\113\301\126\354\027\052\037\153\223\147\163\137"
	"\154\106\273\200\043\305\201\317\111\363\350\365\310\115\211\035"
	"\344\057\235\162\001\371\050\300\117\103\307\246\075\001\072\276"
	"\210\170\001\303\122\017\355\130\004\276\145\255\157\123\275\143"
	"\071\317\144\246\162\066\010\243\071\035\122\025\264\324\077\115"
	"\113\070\237\255\372\106\263\365\050\131\320\210\017\002\110\371"
	"\052\310\316\221\176\317\070\160\052\052\010\014\173\262\132\267"
	"\037\004\375\143\342\117\116\121\363\376\356\352\131\262\247\144"
	"\276\334\071\205\223\063\012\265\336\332\240\350\223\165\345\217"
	"\003\025\170\331\313\213\062\021\054\113\003\137\314\103\305\254"
	"\356\076\357\027\165\301\362\070\055\107\150\224\151\204\041\164"
	"\305\202\307\151\137\153\172\222\260\015\371\304\156\160\257\152"
	"\062\056\363\363\015\257\247\200\222\100\231\076\020\217\246\341"
	"\123\027\237\071\135\324\365\223\353\160\165\300\155\075\122\343"
	"\125\320\301\117\225\247\010\200\216\342\361\124\014\010\345\107"
	"\372\107\373\207\227\222\203\021\360\027\341\113\225\067\341\257"
#define      chk2_z	19
#define      chk2	((&data[2823]))
	"\245\161\352\343\220\300\150\211\131\053\330\171\034\260\060\117"
	"\031\307\224\345\253"
#define      pswd_z	256
#define      pswd	((&data[2871]))
	"\240\027\315\175\253\265\252\245\375\246\054\224\070\260\246\051"
	"\307\207\164\135\276\126\014\247\343\074\114\125\214\247\325\257"
	"\250\313\370\044\341\245\055\234\132\017\121\344\160\106\112\045"
	"\315\061\024\336\026\137\074\052\161\014\036\071\263\363\350\134"
	"\276\340\201\240\206\256\074\340\276\216\305\056\324\017\123\242"
	"\101\150\200\130\310\275\202\071\311\240\162\174\224\132\331\122"
	"\073\132\363\302\011\057\243\307\275\150\366\222\170\112\065\271"
	"\262\266\021\172\163\224\263\074\065\046\271\311\200\222\034\274"
	"\354\017\176\365\077\041\274\374\212\263\217\002\375\305\273\257"
	"\173\315\052\356\142\336\053\227\004\344\140\205\166\174\101\143"
	"\213\300\130\312\341\025\307\154\310\127\156\306\034\052\165\230"
	"\367\237\206\131\175\262\361\202\226\121\007\015\316\111\160\132"
	"\011\311\045\353\337\354\127\247\104\306\156\141\360\343\371\350"
	"\203\200\102\001\062\063\203\311\205\212\326\123\323\107\255\335"
	"\020\322\310\357\277\040\227\004\346\005\145\327\351\136\277\154"
	"\337\001\155\021\065\360\333\272\173\261\016\117\371\274\054\011"
	"\216\365\371\116\026\221\122\375\227\267\324\200\026\224\355\365"
	"\225\133\007\313\113\342\206\307\224\224\027\215\120\277\105\054"
	"\326\023\252\201\311\125\047\306\373\124\133\063\004\001\134\314"
	"\210\321\052\106\050\067\356\013\163\073\141\377\372\247\054\320"
	"\272\326\122\203\054\172\112\047\316\245\132\323\247\267\240\057"
	"\211\312\166\261\001\145\275\164\240"
#define      msg1_z	65
#define      msg1	((&data[3194]))
	"\305\240\153\200\167\276\004\265\265\127\000\301\177\104\337\372"
	"\117\060\374\345\013\303\131\133\270\167\244\003\070\003\036\151"
	"\235\070\240\222\322\271\215\051\071\062\225\156\307\167\004\350"
	"\133\310\066\045\150\065\313\304\305\057\146\327\113\306\320\270"
	"\253\100\306\161\046\165\250\226\243\070\116\312\007\364\045\333"
	"\233\334"
#define      date_z	1
#define      date	((&data[3269]))
	"\203"/* End of data[] */;
#define      hide_z	4096
#define SETUID 0	/* Define as 1 to call setuid(0) at start of script */
#define DEBUGEXEC	0	/* Define as 1 to debug execvp calls */
#define TRACEABLE	1	/* Define as 1 to enable ptrace the executable */
#define HARDENING	0	/* Define as 1 to disable ptrace/dump the executable */
#define BUSYBOXON	0	/* Define as 1 to enable work with busybox */

#if HARDENING
static const char * shc_x[] = {
"/*",
" * Copyright 2019 - Intika <intika@librefox.org>",
" * Replace ******** with secret read from fd 21",
" * Also change arguments location of sub commands (sh script commands)",
" * gcc -Wall -fpic -shared -o shc_secret.so shc_secret.c -ldl",
" */",
"",
"#define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */",
"#define PLACEHOLDER \"********\"",
"#include <dlfcn.h>",
"#include <stdlib.h>",
"#include <string.h>",
"#include <unistd.h>",
"#include <stdio.h>",
"#include <signal.h>",
"",
"static char secret[128000]; //max size",
"typedef int (*pfi)(int, char **, char **);",
"static pfi real_main;",
"",
"// copy argv to new location",
"char **copyargs(int argc, char** argv){",
"    char **newargv = malloc((argc+1)*sizeof(*argv));",
"    char *from,*to;",
"    int i,len;",
"",
"    for(i = 0; i<argc; i++){",
"        from = argv[i];",
"        len = strlen(from)+1;",
"        to = malloc(len);",
"        memcpy(to,from,len);",
"        // zap old argv space",
"        memset(from,'\\0',len);",
"        newargv[i] = to;",
"        argv[i] = 0;",
"    }",
"    newargv[argc] = 0;",
"    return newargv;",
"}",
"",
"static int mymain(int argc, char** argv, char** env) {",
"    //fprintf(stderr, \"Inject main argc = %d\\n\", argc);",
"    return real_main(argc, copyargs(argc,argv), env);",
"}",
"",
"int __libc_start_main(int (*main) (int, char**, char**),",
"                      int argc,",
"                      char **argv,",
"                      void (*init) (void),",
"                      void (*fini)(void),",
"                      void (*rtld_fini)(void),",
"                      void (*stack_end)){",
"    static int (*real___libc_start_main)() = NULL;",
"    int n;",
"",
"    if (!real___libc_start_main) {",
"        real___libc_start_main = dlsym(RTLD_NEXT, \"__libc_start_main\");",
"        if (!real___libc_start_main) abort();",
"    }",
"",
"    n = read(21, secret, sizeof(secret));",
"    if (n > 0) {",
"      int i;",
"",
"    if (secret[n - 1] == '\\n') secret[--n] = '\\0';",
"    for (i = 1; i < argc; i++)",
"        if (strcmp(argv[i], PLACEHOLDER) == 0)",
"          argv[i] = secret;",
"    }",
"",
"    real_main = main;",
"",
"    return real___libc_start_main(mymain, argc, argv, init, fini, rtld_fini, stack_end);",
"}",
"",
0};
#endif /* HARDENING */

/* rtc.c */

#include <sys/stat.h>
#include <sys/types.h>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

/* 'Alleged RC4' */

static unsigned char stte[256], indx, jndx, kndx;

/*
 * Reset arc4 stte. 
 */
void stte_0(void)
{
	indx = jndx = kndx = 0;
	do {
		stte[indx] = indx;
	} while (++indx);
}

/*
 * Set key. Can be used more than once. 
 */
void key(void * str, int len)
{
	unsigned char tmp, * ptr = (unsigned char *)str;
	while (len > 0) {
		do {
			tmp = stte[indx];
			kndx += tmp;
			kndx += ptr[(int)indx % len];
			stte[indx] = stte[kndx];
			stte[kndx] = tmp;
		} while (++indx);
		ptr += 256;
		len -= 256;
	}
}

/*
 * Crypt data. 
 */
void arc4(void * str, int len)
{
	unsigned char tmp, * ptr = (unsigned char *)str;
	while (len > 0) {
		indx++;
		tmp = stte[indx];
		jndx += tmp;
		stte[indx] = stte[jndx];
		stte[jndx] = tmp;
		tmp += stte[indx];
		*ptr ^= stte[tmp];
		ptr++;
		len--;
	}
}

/* End of ARC4 */

#if HARDENING

#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/prctl.h>
#define PR_SET_PTRACER 0x59616d61

/* Seccomp Sandboxing Init */
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <sys/socket.h>

#include <linux/filter.h>
#include <linux/seccomp.h>
#include <linux/audit.h>

#define ArchField offsetof(struct seccomp_data, arch)

#define Allow(syscall) \
    BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SYS_##syscall, 0, 1), \
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)

struct sock_filter filter[] = {
    /* validate arch */
    BPF_STMT(BPF_LD+BPF_W+BPF_ABS, ArchField),
    BPF_JUMP( BPF_JMP+BPF_JEQ+BPF_K, AUDIT_ARCH_X86_64, 1, 0),
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),

    /* load syscall */
    BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)),

    /* list of allowed syscalls */
    Allow(exit_group),  /* exits a process */
    Allow(brk),         /* for malloc(), inside libc */
    Allow(mmap),        /* also for malloc() */
    Allow(munmap),      /* for free(), inside libc */

    /* and if we don't match above, die */
    BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),
};
struct sock_fprog filterprog = {
    .len = sizeof(filter)/sizeof(filter[0]),
    .filter = filter
};

/* Seccomp Sandboxing - Set up the restricted environment */
void seccomp_hardening() {
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
        perror("Could not start seccomp:");
        exit(1);
    }
    if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &filterprog) == -1) {
        perror("Could not start seccomp:");
        exit(1);
    }
} 
/* End Seccomp Sandboxing Init */

void shc_x_file() {
    FILE *fp;
    int line = 0;

    if ((fp = fopen("/tmp/shc_x.c", "w")) == NULL ) {exit(1); exit(1);}
    for (line = 0; shc_x[line]; line++)	fprintf(fp, "%s\n", shc_x[line]);
    fflush(fp);fclose(fp);
}

int make() {
	char * cc, * cflags, * ldflags;
    char cmd[4096];

	cc = getenv("CC");
	if (!cc) cc = "cc";

	sprintf(cmd, "%s %s -o %s %s", cc, "-Wall -fpic -shared", "/tmp/shc_x.so", "/tmp/shc_x.c -ldl");
	if (system(cmd)) {remove("/tmp/shc_x.c"); return -1;}
	remove("/tmp/shc_x.c"); return 0;
}

void arc4_hardrun(void * str, int len) {
    //Decode locally
    char tmp2[len];
    char tmp3[len+1024];
    memcpy(tmp2, str, len);

	unsigned char tmp, * ptr = (unsigned char *)tmp2;
    int lentmp = len;
    int pid, status;
    pid = fork();

    shc_x_file();
    if (make()) {exit(1);}

    setenv("LD_PRELOAD","/tmp/shc_x.so",1);

    if(pid==0) {

        //Start tracing to protect from dump & trace
        if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
            kill(getpid(), SIGKILL);
            _exit(1);
        }

        //Decode Bash
        while (len > 0) {
            indx++;
            tmp = stte[indx];
            jndx += tmp;
            stte[indx] = stte[jndx];
            stte[jndx] = tmp;
            tmp += stte[indx];
            *ptr ^= stte[tmp];
            ptr++;
            len--;
        }

        //Do the magic
        sprintf(tmp3, "%s %s", "'********' 21<<<", tmp2);

        //Exec bash script //fork execl with 'sh -c'
        system(tmp2);

        //Empty script variable
        memcpy(tmp2, str, lentmp);

        //Clean temp
        remove("/tmp/shc_x.so");

        //Sinal to detach ptrace
        ptrace(PTRACE_DETACH, 0, 0, 0);
        exit(0);
    }
    else {wait(&status);}

    /* Seccomp Sandboxing - Start */
    seccomp_hardening();

    exit(0);
}
#endif /* HARDENING */

/*
 * Key with file invariants. 
 */
int key_with_file(char * file)
{
	struct stat statf[1];
	struct stat control[1];

	if (stat(file, statf) < 0)
		return -1;

	/* Turn on stable fields */
	memset(control, 0, sizeof(control));
	control->st_ino = statf->st_ino;
	control->st_dev = statf->st_dev;
	control->st_rdev = statf->st_rdev;
	control->st_uid = statf->st_uid;
	control->st_gid = statf->st_gid;
	control->st_size = statf->st_size;
	control->st_mtime = statf->st_mtime;
	control->st_ctime = statf->st_ctime;
	key(control, sizeof(control));
	return 0;
}

#if DEBUGEXEC
void debugexec(char * sh11, int argc, char ** argv)
{
	int i;
	fprintf(stderr, "shll=%s\n", sh11 ? sh11 : "<null>");
	fprintf(stderr, "argc=%d\n", argc);
	if (!argv) {
		fprintf(stderr, "argv=<null>\n");
	} else { 
		for (i = 0; i <= argc ; i++)
			fprintf(stderr, "argv[%d]=%.60s\n", i, argv[i] ? argv[i] : "<null>");
	}
}
#endif /* DEBUGEXEC */

void rmarg(char ** argv, char * arg)
{
	for (; argv && *argv && *argv != arg; argv++);
	for (; argv && *argv; argv++)
		*argv = argv[1];
}

void chkenv_end(void);

int chkenv(int argc)
{
	char buff[512];
	unsigned long mask, m;
	int l, a, c;
	char * string;
	extern char ** environ;

	mask = (unsigned long)getpid();
	stte_0();
	 key(&chkenv, (void*)&chkenv_end - (void*)&chkenv);
	 key(&data, sizeof(data));
	 key(&mask, sizeof(mask));
	arc4(&mask, sizeof(mask));
	sprintf(buff, "x%lx", mask);
	string = getenv(buff);
#if DEBUGEXEC
	fprintf(stderr, "getenv(%s)=%s\n", buff, string ? string : "<null>");
#endif
	l = strlen(buff);
	if (!string) {
		/* 1st */
		sprintf(&buff[l], "=%lu %d", mask, argc);
		putenv(strdup(buff));
		return 0;
	}
	c = sscanf(string, "%lu %d%c", &m, &a, buff);
	if (c == 2 && m == mask) {
		/* 3rd */
		rmarg(environ, &string[-l - 1]);
		return 1 + (argc - a);
	}
	return -1;
}

void chkenv_end(void){}

#if HARDENING

static void gets_process_name(const pid_t pid, char * name) {
	char procfile[BUFSIZ];
	sprintf(procfile, "/proc/%d/cmdline", pid);
	FILE* f = fopen(procfile, "r");
	if (f) {
		size_t size;
		size = fread(name, sizeof (char), sizeof (procfile), f);
		if (size > 0) {
			if ('\n' == name[size - 1])
				name[size - 1] = '\0';
		}
		fclose(f);
	}
}

void hardening() {
    prctl(PR_SET_DUMPABLE, 0);
    prctl(PR_SET_PTRACER, -1);

    int pid = getppid();
    char name[256] = {0};
    gets_process_name(pid, name);

    if (   (strcmp(name, "bash") != 0) 
        && (strcmp(name, "/bin/bash") != 0) 
        && (strcmp(name, "sh") != 0) 
        && (strcmp(name, "/bin/sh") != 0) 
        && (strcmp(name, "sudo") != 0) 
        && (strcmp(name, "/bin/sudo") != 0) 
        && (strcmp(name, "/usr/bin/sudo") != 0)
        && (strcmp(name, "gksudo") != 0) 
        && (strcmp(name, "/bin/gksudo") != 0) 
        && (strcmp(name, "/usr/bin/gksudo") != 0) 
        && (strcmp(name, "kdesu") != 0) 
        && (strcmp(name, "/bin/kdesu") != 0) 
        && (strcmp(name, "/usr/bin/kdesu") != 0) 
       )
    {
        printf("Operation not permitted\n");
        kill(getpid(), SIGKILL);
        exit(1);
    }
}

#endif /* HARDENING */

#if !TRACEABLE

#define _LINUX_SOURCE_COMPAT
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

#if !defined(PT_ATTACHEXC) /* New replacement for PT_ATTACH */
   #if !defined(PTRACE_ATTACH) && defined(PT_ATTACH)
       #define PT_ATTACHEXC	PT_ATTACH
   #elif defined(PTRACE_ATTACH)
       #define PT_ATTACHEXC PTRACE_ATTACH
   #endif
#endif

void untraceable(char * argv0)
{
	char proc[80];
	int pid, mine;

	switch(pid = fork()) {
	case  0:
		pid = getppid();
		/* For problematic SunOS ptrace */
#if defined(__FreeBSD__)
		sprintf(proc, "/proc/%d/mem", (int)pid);
#else
		sprintf(proc, "/proc/%d/as",  (int)pid);
#endif
		close(0);
		mine = !open(proc, O_RDWR|O_EXCL);
		if (!mine && errno != EBUSY)
			mine = !ptrace(PT_ATTACHEXC, pid, 0, 0);
		if (mine) {
			kill(pid, SIGCONT);
		} else {
			perror(argv0);
			kill(pid, SIGKILL);
		}
		_exit(mine);
	case -1:
		break;
	default:
		if (pid == waitpid(pid, 0, 0))
			return;
	}
	perror(argv0);
	_exit(1);
}
#endif /* !TRACEABLE */

char * xsh(int argc, char ** argv)
{
	char * scrpt;
	int ret, i, j;
	char ** varg;
	char * me = argv[0];
	if (me == NULL) { me = getenv("_"); }
	if (me == 0) { fprintf(stderr, "E: neither argv[0] nor $_ works."); exit(1); }

	ret = chkenv(argc);
	stte_0();
	 key(pswd, pswd_z);
	arc4(msg1, msg1_z);
	arc4(date, date_z);
	if (date[0] && (atoll(date)<time(NULL)))
		return msg1;
	arc4(shll, shll_z);
	arc4(inlo, inlo_z);
	arc4(xecc, xecc_z);
	arc4(lsto, lsto_z);
	arc4(tst1, tst1_z);
	 key(tst1, tst1_z);
	arc4(chk1, chk1_z);
	if ((chk1_z != tst1_z) || memcmp(tst1, chk1, tst1_z))
		return tst1;
	arc4(msg2, msg2_z);
	if (ret < 0)
		return msg2;
	varg = (char **)calloc(argc + 10, sizeof(char *));
	if (!varg)
		return 0;
	if (ret) {
		arc4(rlax, rlax_z);
		if (!rlax[0] && key_with_file(shll))
			return shll;
		arc4(opts, opts_z);
#if HARDENING
	    arc4_hardrun(text, text_z);
	    exit(0);
       /* Seccomp Sandboxing - Start */
       seccomp_hardening();
#endif
		arc4(text, text_z);
		arc4(tst2, tst2_z);
		 key(tst2, tst2_z);
		arc4(chk2, chk2_z);
		if ((chk2_z != tst2_z) || memcmp(tst2, chk2, tst2_z))
			return tst2;
		/* Prepend hide_z spaces to script text to hide it. */
		scrpt = malloc(hide_z + text_z);
		if (!scrpt)
			return 0;
		memset(scrpt, (int) ' ', hide_z);
		memcpy(&scrpt[hide_z], text, text_z);
	} else {			/* Reexecute */
		if (*xecc) {
			scrpt = malloc(512);
			if (!scrpt)
				return 0;
			sprintf(scrpt, xecc, me);
		} else {
			scrpt = me;
		}
	}
	j = 0;
#if BUSYBOXON
	varg[j++] = "busybox";
	varg[j++] = "sh";
#else
	varg[j++] = argv[0];		/* My own name at execution */
#endif
	if (ret && *opts)
		varg[j++] = opts;	/* Options on 1st line of code */
	if (*inlo)
		varg[j++] = inlo;	/* Option introducing inline code */
	varg[j++] = scrpt;		/* The script itself */
	if (*lsto)
		varg[j++] = lsto;	/* Option meaning last option */
	i = (ret > 1) ? ret : 0;	/* Args numbering correction */
	while (i < argc)
		varg[j++] = argv[i++];	/* Main run-time arguments */
	varg[j] = 0;			/* NULL terminated array */
#if DEBUGEXEC
	debugexec(shll, j, varg);
#endif
	execvp(shll, varg);
	return shll;
}

int main(int argc, char ** argv)
{
#if SETUID
   setuid(0);
#endif
#if DEBUGEXEC
	debugexec("main", argc, argv);
#endif
#if HARDENING
	hardening();
#endif
#if !TRACEABLE
	untraceable(argv[0]);
#endif
	argv[1] = xsh(argc, argv);
	fprintf(stderr, "%s%s%s: %s\n", argv[0],
		errno ? ": " : "",
		errno ? strerror(errno) : "",
		argv[1] ? argv[1] : "<null>"
	);
	return 1;
}
